#include <stdio.h>
#include <stdlib.h>
#include <sys/epoll.h>
#include <unistd.h>
#define MAX_EVENTS 64

int main(void) {
	int epfd, nr_events, i, ret, fd, fd2;
	struct epoll_event *events;
	fd = STDIN_FILENO;
	fd2 = STDOUT_FILENO;
	events = malloc(sizeof(struct epoll_event) * MAX_EVENTS);
	if(!events) {
		perror("malloc");
		return 1;
	}
	epfd = epoll_create1(0);
	if(epfd < 0) {
		perror("epfd_create1");
		return 1;
	}
	events->data.fd = fd;
	events->events = EPOLLIN | EPOLLOUT;
	ret = epoll_ctl(epfd, EPOLL_CTL_ADD, fd, events);
	events++;
	events->data.fd = fd2;
	events->events = EPOLLIN | EPOLLOUT;

	ret = epoll_ctl(epfd, EPOLL_CTL_ADD, fd2, events);

	nr_events = epoll_wait(epfd, events, MAX_EVENTS, -1);
	if(nr_events < 0) {
		perror("epoll_wait");
		return 1;
	}
	for(i=0; i < nr_events; i++)
		printf("zdarzenie=%d dla fd=%d\n", events[i].events, events[i].data.fd);
	free(events);

	return 0;
}
